package com.yunbiao.ybbusstopplate.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.yunbiao.ybbusstopplate.R;

public class LetterErrorDialog extends Dialog {

    private Context context;
    private View view;
    private TextView tv_tip,tv_error_title;
    private Button btn_confirm;
    private String tip,title;
    private OnConfimBtnClickListener onConfimBtnClickListener;

    public LetterErrorDialog(Context context,String tip,String title) {
        super(context);
        this.context=context;
        this.tip=tip;
        this.title=title;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        view=LayoutInflater.from(context).inflate(R.layout.dialog_letter_error,null);
        setContentView(view);

        tv_tip=view.findViewById(R.id.tv_error_tip);
        tv_error_title=view.findViewById(R.id.tv_error_title);
        btn_confirm=view.findViewById(R.id.btn_error_confim);

        setCancelable(false);
        setCanceledOnTouchOutside(false);

        initData();
    }

    public void setOnConfimBtnClickListener(OnConfimBtnClickListener listener){
        this.onConfimBtnClickListener=listener;
    }

    private void initData(){
        if (!TextUtils.isEmpty(title)){
            tv_error_title.setText(title);
        }
        tv_tip.setText("只支持"+tip+"设备，如有任何问题");
        btn_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
                if (onConfimBtnClickListener!=null){
                    onConfimBtnClickListener.onClick(LetterErrorDialog.this);
                }
            }
        });
    }

    public interface OnConfimBtnClickListener{
        void onClick(Dialog dialog);
    }
}
